package com.qq.supplier.mapper;

import com.qq.supplier.entity.Car;
import com.qq.supplier.entity.CarIn;
import com.qq.supplier.entity.Order_info;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface CarMapper {

    //添加车辆信息--车辆入库
    @Insert("insert into car(id,car_var,car_name,car_version,car_color,car_address,car_source,car_indate,car_inprice,car_total,car_allprice) values(null,#{carVar},#{carName},#{carVersion},#{carColor},#{carAddress},#{carSource},#{carInDate},#{carInPrice},#{carTotal},#{carTotalPrice})")
    int addCar(Car car);

    //查询所有车辆信息--进货页
    @Select("select * from car")
    List<Car> queryAll();

    //进货页面中  修改某一类车辆数量
    @Update("update car set car_var=#{carVar},car_name=#{carName},car_version=#{carVersion},car_color=#{carColor},car_address=#{carAddress},car_source=#{carSource},car_indate=#{carInDate},car_inprice=#{carInPrice},car_total=#{carTotal},car_allprice=#{carTotalPrice} where car.id=#{id} ")
    int editCar(Car car);

    //在库存页--主页面通过id查询某一类车辆的信息
    @Select("select * from car_in ci where ci.id=#{id}")
    CarIn queryOne(String id);

    //主页面中  修改某一类车辆信息
    @Update("update car_in ci set car_vars=#{carVars},car_names=#{carNames},car_versions=#{carVersions},car_colors=#{carColors},car_addresss=#{carAddresss},car_sources=#{carSources},car_indates=#{carInDates},car_inprices=#{carInPrices},car_totals=#{carTotals},car_outs=#{carOuts} where ci.id=#{id}")
    int editCarIn(CarIn carIn);

    //车辆仓库主页  显示库存
    @Select("select * from car_in")
    List<CarIn> querys();

    //在库存添加数据
    @Insert("insert into car_in(id,car_vars,car_names,car_versions,car_colors,car_addresss,car_sources,car_indates,car_inprices,car_totals) values(null,#{carVar},#{carName},#{carVersion},#{carColor},#{carAddress},#{carSource},#{carInDate},#{carInPrice},#{carTotal})")
    int addCarIn(Car car); //主页面中那个添加car类

    //根据条件查询数据库里面的数据----查的是库存表
    @Select("select * from car_in where car_vars=#{carVar} and car_names=#{carName} and car_versions=#{carVersion} and car_colors=#{carColor} and car_addresss=#{carAddress} and car_sources=#{carSource}")
    CarIn select(Car car);

    //展示车辆出库信息---详情页
    @Select("select * from order_info oi where oi.brand=#{brand} and oi.type=#{type}")
    List<Order_info> selects(String brand, String type);

/*    //通过车辆类型查找车辆数量--制作图表分析
    @Select("SELECT SUM(car_total) FROM car where car_var = #{carVar} and QUARTER(car_indate)=QUARTER(NOW())")
    List<Car> SelectCars(String carVar, Date carInDate);*/

}
